const WebSocket = require('ws'); //引入ws, websocket通讯模块

//创建服务端对象wss
const wss = new WebSocket.Server({ port: 8081});

//开始监听8081端口
wss.on('connection', function (ws) {
    console.log(`[SERVER] connection()`);
     
    //绑定事件方法message,
    ws.on('message', function (message) {
        console.log(`[SERVER] Received: ${message}`);
        ws.send(`ECHO: ${message}`); //接收消息立即发送信息
    })

    //绑定事件方法find
    ws.on('find', content => {
        console.log(`[SERVER] Received: ${content}`);
    })
});
